<template>
	<view class="safe-area-inset-bottom">
		<view class="swip_header">
			<view class="slot-box">
				<view style="width: 100%;">
					<uni-search-bar v-model="queryParams.params.contractNameAndContractNumber" type="text" @confirm="handleQuery" @input="handleQuery" placeholder="请输入合同名称 / 合同编号" />
				</view>
			</view>
		</view>
		
		<!-- 列表 -->
		<view v-if="contractList != ''" class="listSearchTop cardList">
		<uni-card :is-shadow="false" v-for="(item,index) in contractList" :key="index" @click="handleView(item)">
			<p class="grid-hidden contract_Name">{{ item.contractName }}</p>
			<p class="grid-integral">合同编号：{{ item.contractNumber }}</p>
			<p class="grid-integral">业务分类：{{ item.contractTypeName }}<span style="margin: 0 6rpx;">>></span>{{ item.businessTypeName }}</p>
			<p class="grid-hidden">签约方：{{ item.signCompanyAllName }}</p>
			<p class="grid-integral">经办人：{{item.signerName}}</p>
			<p class="grid-integral">合同有效期：{{item.createTime}}
			<span v-if="!!item.contractEndTime">到{{item.contractEndTime}}</span>
			<span v-else style="margin-left:10rpx">终止日期暂无</span></p>
				<p class="grid-integral">归档时间：{{item.updateTime}}</p>
				<view slot="actions" class="card-actions">
					<view>合同状态：
						<template v-for="(dictItem, index) in dicts.contract_sign_flow_status">
						  <template v-if="item.status == dictItem.value">
							<span class="themeColor">{{dictItem.text}}</span>
						  </template>
						</template>			  
					</view>
				  <view class="card-actions-item" @click.stop="handleDelete(item,index)">
				    <text class="card-actions-item-text errorColor">删除</text>
				  </view>
				</view>
			</uni-card>
		<!-- 加载更多 -->
		<uni-load-more color="#00a660" :status="loadStatus"/>
		</view>
		<!-- 暂无数据 -->
		<luanqingEmpty :show="true" text="没有更多数据啦" v-else />
	</view>
</template>

<script>
	import {getDictsByNameForUni} from "@/utils/dicts";
	import {listContractArchiveslistInvalidContract} from "@/api/ec/work/contract/contractArchives";
	import { delContractSignMine } from "@/api/ec/work/contract/contractSign";
	import luanqingEmpty from '@/components/luanqing-empty/luanqing-empty';
	export default {
		components:{luanqingEmpty,},
		data() {
			return {
				dicts:{
					contract_sign_flow_status:[]
				},
				total:0 ,//总条数
				loadStatus:'loading', //是否加载中 //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				contractList: [], // 合同类型列表
			    // 查询参数
			     queryParams: {
			            pageNum: 1,
			            pageSize: 10,
			            signerName: null,
			            signCompanyAllName:null,
			            contractName: null,
			            params:{
			              contractNameAndContractNumber:null,
			            },
			    },       
			}
		},
		onLoad() {
			this.getList();
			this.getDicts()
		},
		//上拉触底函数
		onReachBottom() { 
			if (this.loadStatus != 'noMore' && this.total > this.contractList.length) {
			  this.loadStatus = 'loading';
			  // 延迟500毫秒显示loading效果
			  setTimeout(() => {
			    // 执行查询的方法
			    this.getList(false);
			  }, 500)
			} else {
			  // 停止加载
			  this.loadStatus = 'noMore'
			}          
		},
		methods: {
			/**加载数据字典*/
			getDicts() {
			  this.dicts.contract_sign_flow_status = getDictsByNameForUni("contract_sign_flow_status");
			},
			/** 搜索 */
			handleQuery(){
				this.getList(true);      
			},
			/** 获取列表 */
			getList(reload) {
			  if (reload) {
			    this.queryParams.pageNum = 1;
			    this.loadStatus = 'more'
			    uni.showLoading({title: '加载中...', mask: true});
			  }
			  listContractArchiveslistInvalidContract(this.queryParams).then(response => {
			    if (reload) {
			      uni.hideLoading()
			    }
			    this.total = response.total;
			    if (response.total > 0) {
			      const dataRows = response.rows;
			      this.contractList = reload ? dataRows : this.contractList.concat(dataRows);
			    } else {
			      this.contractList = [];
			    }
			    // 判断数据是否加载完全
			    if (response.total <= this.contractList.length) {
			      this.loadStatus = 'noMore'
			    }
			    // 页数+1
			    this.queryParams.pageNum++
			  }).catch(() => {
			    if (reload) {
			      uni.hideLoading()
			    }
			  });
			},
			/** 查看 */
			handleView(row){
				this.$tab.navigateTo(`/pages/sign/detail?id=${row.contractId}&flowId=${row.id}`)
			},
			/** 删除 */
			handleDelete(row,index){
				var _this = this
				uni.showModal({
					title:'系统提示',
					content:'是否删除合同？',
					confirmColor:'#00a660',
					success:function(res){
						if(res.confirm){
							delContractSignMine(row.id);
							_this.contractList.splice(index,1)
							_this.$modal.msgSuccess("删除成功");
						}
					}				
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	page {
		background:$uni-bg-color-grey;
	}
</style>
